package com.wg.dome.handle;

import com.wg.dome.ClientPeer;
import com.wg.dome.ErrorHelper;
import com.wg.dome.chat.ChatLobby;
import com.wg.dome.operation.ExitChatRequest;
import com.wg.core.net.OperationRequest;
import com.wg.core.net.OperationResponse;
import com.wg.core.net.SendParameters;

/**
 * 取消订阅聊天频道
 */
public class HandleRequest12 extends BaseHandle {

    @Override
    public OperationResponse execute(ClientPeer peer, OperationRequest request, SendParameters sendParameters) {
        ExitChatRequest chatRequest = new ExitChatRequest(request);
        if (!chatRequest.isValid()) {
            return ErrorHelper.getInvalidResponse(chatRequest);
        }

        ChatLobby chatLobby = peer.getApplication().getChatLobby();
        chatLobby.onRemoveChannel(chatRequest.getChannel(), peer);
        return new OperationResponse(request.getOperationCode());
    }
}
